<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
  <title>TCPlayer 直播播放</title>
  <!-- 引入 TCPlayer 样式和脚本 -->
  <!-- https://web.sdk.qcloud.com/player/tcplayer/release/v5.1.0/tcplayer.min.css -->
  <link href="./tcplayer/tcplayer.min.css" rel="stylesheet"/>
  <style>
  	  body{
  		  padding: 0;
  		  margin:0;
  	  }
  </style>
</head>
<body>
  <!-- 播放器容器 -->
  <video id="player" class="tcplayer" controls height="262" style="width:100%" preload="auto" playsinline webkit-playsinline></video>
  <script src="./tcplayer/TXLivePlayer-1.3.0.min.js"></script>
  <script src="./tcplayer/hls.min.1.1.6.js"></script>
  <script src="./tcplayer/flv.min.1.6.3.js"></script>
  <script src="./tcplayer/tcplayer.v4.8.0.min.js"></script>
  <script type="text/javascript" src="./tcplayer/uni.webview.1.5.4.js"></script>
  <script>
    // 从 URL 参数获取直播地址
    function getUrlParam(name) {
      const params = new URLSearchParams(window.location.search);
	  console.log('params',params)
      return params.get(name);
    }
    if(getUrlParam('url')){
		console.log('urlSSS', getUrlParam('url'))
		// 初始化播放器
		const player = TCPlayer('player', {
		  sources: [{
		    src: getUrlParam('url'),//getUrlParam('url') || 'https://player.xueqianban.vip/live/3f6aa66c-822c-4b82-aada-176755c99788.m3u8?txSecret=1feb03b636471f0995681c3892b28e0f&txTime=6881ADF8', // 默认地址
		    // type: 'application/x-mpegURL' // HLS 格式
		  }],
		  controlBar: {
			  playToggle:false
		  },
		  autoplay: true,
		  poster: getUrlParam('thumbnail'), // 封面图
		  licenseUrl: 'license/url',
		});
		// 全屏状态切换时触发
		player.on('fullscreenchange', (event) => {
			 console.log('全屏状态切换时触发:', event.detail, player.isFullscreen());
			 // plus.screen.lockOrientation('landscape');  // 强制横屏  [^791^]
			// let isFull = event.detail.fullscreen;  // true = 全屏，false = 小屏
		   if (player.isFullscreen()) {
			 console.log('进入全屏');
			 // 可选：锁横屏
			 // #ifdef APP-PLUS
			 plus.screen.lockOrientation('landscape');
			 // #endif
		   } else {
			 console.log('退出全屏');
			 // #ifdef APP-PLUS
			 plus.screen.unlockOrientation();
			 plus.screen.lockOrientation('portrait-primary'); // 恢复竖屏
			 // #endif
		   }
		})
		// 获取事件状态码
		player.on('webrtcevent', function(event) {
		   // 从回调参数 event 中获取事件状态码及相关数据
		    console.log('获取事件状态码:', event);
		});
		// 监听错误事件
		player.on('error', (error) => {
		  console.log('播放错误:', error);
		  uni.postMessage({
			  data: {
				   type: 'error'
			  }
		  })
		  // player.load(getUrlParam('url'));
		  // player.dispose(); // 销毁播放器
		  // document.body.innerHTML += `
		  //   <video id="player" class="tcplayer" controls  style="height: 240px;width:100%" preload="auto" playsinline webkit-playsinline></video>
		  // `;
		  // setTimeout(() => {
			 //  player = TCPlayer('player', {
			 //    sources: [{
			 //      src: getUrlParam('url'),//getUrlParam('url') || 'https://player.xueqianban.vip/live/3f6aa66c-822c-4b82-aada-176755c99788.m3u8?txSecret=1feb03b636471f0995681c3892b28e0f&txTime=6881ADF8', // 默认地址
			 //    }],
			 //    autoplay: true,
			 //    poster: '', // 封面图
			 //  });
		  // }, 3000)
		});
	}

  </script>
</body>
</html>